class BatchesController < ApplicationController
  def new
    @title = "Batch Scan"
    # mark a batch with the session id and then load them
    sid = session[:session_id]
    Report.checkout_batch(sid)
    @reports = Report.batch(sid)
  end
  
  def finish
    finish_batch
    redirect_to(reports_path)
  end
  
  def finish_and_scan_another
    finish_batch
    redirect_to(:action => :new)
  end
  
  def cancel
    Report.release_batch(session[:session_id])
    flash[:success] = "You successfully cancelled scanning."
    redirect_to(reports_path)
  end

  private
    def finish_batch
      ids = {}
      ids[:yes] = params[:selected].keys.collect{|k| k.to_s} rescue []
      ids[:no] = params[:all_ids].split(",").reject{|id| ids[:yes].include?(id)}
      flash[:last_batch_time] = Report.update_and_release_batch(session[:session_id], ids)
    end
end
